// kickstart2018roundE
#include<bits/stdc++.h>
using namespace std;
// 法一：O(NlogN) 排序，先喝要过期的
int solve(vector<int> &A, int &N, int &K)
{
    sort(A.begin(), A.end());
    int res = 0;
    int consumed = 0;
    int day = 0;
    for (int i = 0; i < A.size(); ++i)
    {
        if (A[i] > day && consumed < K) 
        {
            res++;
            if (++consumed == K)
            {
                day++;
                consumed = 0;
            }
        }
    }
    return res;
}
// 法二：O(NlogN) 从后往前DP
int solve2(vector<int> &A, int &N, int &K)
{
    vector<int> days(N, 0);
    int res = 0;
    for (int a: A)
    {
        days[min(a, N) - 1]++; //按过期时间放入每一天(桶排序)
    }
    for (int i = N - 1; i > 0; i--)
    {
        res += min(days[i], K);
        if (days[i] > K) days[i - 1] += days[i] - K;
    }
    res += min(days[0], K);
    return res;
}


int main()
{
    int T;
    cin >> T;
    for (int ti = 1; ti <= T; ++ti)
    {
        int N;
        int K;
        cin >> N >> K;
        vector<int> A(N);
        for (int i = 0; i < N; ++i)
        {
            cin >> A[i];
        }
        int res = solve2(A, N, K);
        cout << "Case #" << ti << ": " << res << endl;
    }
    return 0;
}